package Dao.Impl;

import Dao.AdminDAO;
import Model.Admin;
import Model.FinancialProduct;
import Util.DbConnector;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.ResultSetHandler;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;

public class AdminDAOImpl implements AdminDAO {
    private static final Logger logger = LogManager.getLogger(AdminDAOImpl.class);
    private final QueryRunner queryRunner = new QueryRunner();

    public AdminDAOImpl() {
    }

    @Override
    public Admin getAdmin(String username, String password) {
        String sql = "SELECT * FROM Admins WHERE username = ? AND password = ?";
        try (Connection connection = DbConnector.getConnection()){
            BeanHandler<Admin> handler = new BeanHandler<>(Admin.class);
            return queryRunner.query(connection, sql, handler, username, password);
        } catch (SQLException e) {
            logger.error("数据库连接失败", e);
        }
        return null;
    }







}